package com.css.fxfzypg.modules.model.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.model.entity.RescueForceEntity;
import com.css.fxfzypg.modules.model.service.Impl.RescueForceServiceImpl;
import com.css.fxfzypg.modules.model.service.RescueForceService;
import com.css.fxfzypg.modules.model.vo.RescueForceVO;
import com.css.fxfzypg.util.PlatformPageUtils;
import com.css.fxfzypg.util.ResponseCreator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Map;

/**
 * @author xzy
 * @date 2022/9/28 11:19
 **/
@RestController
@Slf4j
@RequestMapping("/rescueForce")
public class RescueForceController {

    @Autowired
    private RescueForceService rescueForceService;

    /***
     * 救援力量需求评估模型分页列表查询
     * @param rescueForceVO
     */
    @GetMapping("/page")
    public RestResponse getPage(RescueForceVO rescueForceVO, HttpServletRequest request){
        int curPage = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
        int pageSize=Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
        Map<String,Object> page=rescueForceService.getPage(rescueForceVO,curPage,pageSize);
        return ResponseCreator.createSuccessResponse(page,"查询成功!");
    }

    /***
     * 救援力量需求评估模型保存
     * @param rescueForceEntity
     */
    @PostMapping("/save")
    public RestResponse save(@Valid @RequestBody RescueForceEntity rescueForceEntity){
        rescueForceService.save(rescueForceEntity);
        return ResponseCreator.createSuccessResponse("","保存成功!");
    }

    /***
     * 救援力量需求评估模型删除
     * @param id
     */
    @PostMapping("/delete/{id}")
    public RestResponse delete(@PathVariable("id")String id){
        rescueForceService.delete(id);
        return ResponseCreator.createSuccessResponse("","删除成功");
    }

    /***
     * 救援力量需求评估模型查看
     * @param id
     */

    @GetMapping("/getModelById")
    public RestResponse getModelById(String id){
        RescueForceEntity rescueForceModel=rescueForceService.getModelById(id);
        return ResponseCreator.createSuccessResponse(rescueForceModel);
    }

    /***
     * 救援力量需求评估模型更新
     * @param rescueForce
     */
    @PostMapping("/update")
    public RestResponse delete(@Valid @RequestBody RescueForceEntity rescueForce){
        rescueForceService.update(rescueForce);
        return ResponseCreator.createSuccessResponse("","修改成功");
    }

    /***模型复制
     *
     * @param
     */
    @GetMapping("/getModelByIdForCopy")
    public RestResponse getModelByIdForCopy(String id){
        RescueForceVO model = rescueForceService.getModelByIdForCopy(id);
        return ResponseCreator.createSuccessResponse(model);
    }

    /***
     * 详情页面计算时默认显示的模型信息
     * @param
     */
    @GetMapping("/getDefaultModel")
    public RestResponse getDefaultModel(@RequestParam String taskId){
        RescueForceEntity rescueForceModel = rescueForceService.getDefaultModel(taskId);
        return ResponseCreator.createSuccessResponse(rescueForceModel);
    }

}
